const app = getApp();
import grace from "../../../utils/grace.js";
import util from "../../../utils/util.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    attendance_date: '',
    attendances: [],
    total: {}
  },
  onLoad() {
    this.$data.attendance_date = util.getCurrentDate();
  },
  bindDateChange: function (e) {
    let that = this;
    let school_id = wx.getStorageSync('school_id')
    that.$data.attendance_date = e.detail.value;
    wx.showLoading({
      title: '加载中...',
    })
    let url = app.globalData.api + '/api/v1.0/report/attendance/' + school_id + '/' + that.$data.attendance_date;
    that.$http.get(url, {token: wx.getStorageSync('token')}).then((res) => {
      if (res.data.code == 0) {
        that.$data.total = res.data.total;
        that.$data.attendances = res.data.data;
      } else if (res.data.code == 10001) {
        wx.navigateTo({
          url: "/pages/common/authorize/index"
        })
      } else {
        that.$data.attendances = [];
      }
      wx.hideLoading();
    }).catch(err => {
      console.log(err.status, err.message);
    })
  },
})